import { LoginDto } from "@/dtos/AuthDto";
import { UserDto } from "@/dtos/UserDto";
import { Inject, Service } from "typedi";
import { UserService } from "./UserService";

@Service()
export class AuthService {
  @Inject()
  private userService!: UserService;

  public async login(loginDto: LoginDto): Promise<UserDto | null> {
    const user = await this.userService.findUserAndPwdByName(loginDto.username);
    if (!user) {
      return null;
    }
    if (user.password !== loginDto.password) {
      return null;
    }
    return this.userService.transformEntity2Dto(user);
  }
}
